#include "Comm.hpp"
#include "Fifo.hpp"
#include <unistd.h>
int main()
{
    //1.获取key
    key_t key = GetShmKeyOrDir();
    cout<<"key: "<< ToHex(key)<<endl;
    //2. 创建共享内促
    int shmid = CreatShm(key, defaultsize);
    std::cout << "shmid: " << shmid << std::endl;

    ShmDebug(shmid);
    //3. 将共享内存和进程进行挂接(关联)
    //客户端和服务端通过同一个shmid拿到同一段共享内存的地址

    char* addr = (char*)ShmAttach(shmid);
    std::cout << "Attach shm success, addr: " << ToHex((uint64_t)addr) << std::endl;


    //引入管道
    Fifo fifo;
    Sync syn;
    syn.OpenReadDir();
    for(;;)
    {
        if(!syn.Wait()) break;
        cout<<"shm content:"<<addr <<endl;
    }
    ShmDatch(addr);
    std::cout << "Detach shm success, addr: " << ToHex((uint64_t)addr) << std::endl;

    //删除共享内存
    DeleteShm(shmid);
    return 0;       
}